#include "VertexBuffer.h"

NS_B2D_BEGIN

VertexBuffer::VertexBuffer(void)
	: mVertexSize(0)
	, mVertexCount(0)
	, mVertexFormat(0)
{

}

VertexBuffer::~VertexBuffer(void)
{

}

void VertexBuffer::resize(size_t VertexCount, VertexFormat format, BufferUsage usage)
{
	mVertexCount = VertexCount;
	mVertexSize = GetVertexSizeFromFormat(format);
	mVertexFormat = format;
	mBufferUsage = usage;
	mBufferSize = mVertexCount * mVertexSize;
	resizeImpl();
}

size_t VertexBuffer::GetVertexSizeFromFormat(VertexFormat format)
{
	size_t size = 0;
	for(size_t i = 0; i < VertexAttribute::COUNT; ++i)
	{
		if( format & (1 << i) )
		{
			size += VertexAttribute::sizes[i];
		}
	}
	return size;
}

NS_B2D_END